﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Incubator.Controls
{
    public partial class QuizResults : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || (int)Session["UserID"] == -1)
                Response.Redirect("main.aspx");

            webRef.Quiz q =Global.incuServ.GetQuiz((int)Session["quizId"]);
            webRef.User u = (webRef.User)Session["User"];
            webRef.Company c = Global.incuServ.GetCompany(u.company_id);

            webRef.QuizStatus qs = Global.incuServ.GetQuizStatus(c, q);
            //display quiz name
            lblQuizName.Text = qs.quiz.name;
            //show questions in table
            int i = 0;
            
            foreach (webRef.QuizQuestion ques in q.questions)
            {
                TableCell tc0 = new TableCell();
                TableCell tc1 = new TableCell();
                TableCell tc2 = new TableCell();
                TableCell tc3 = new TableCell();
                TableRow tr = new TableRow();
                tc0.Controls.Add(new LiteralControl(ques.name));
                tc1.Controls.Add(new LiteralControl(qs.answers[i]));
                tc2.Controls.Add(new LiteralControl(ques.answer));
                int profit = (qs.answers[i] == ques.answer) ? ques.value : 0;
                tc3.Controls.Add(new LiteralControl(profit.ToString()+"/"+ques.value.ToString()));
                tr.Cells.Add(tc0);
                tr.Cells.Add(tc1);
                tr.Cells.Add(tc2);
                tr.Cells.Add(tc3);
                tblQuizzResult.Rows.Add(tr);
                ++i;
            }


            

        }
    }
}